package cn.itcast.controller;

import cn.itcast.domain.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/user/*")
public class UserServlet extends BaseServlet {
    // TODO: 2020年7月17日22:14:35    登录验证
    private void login(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        //获取页面传递参数
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        //System.out.println(username+":"+ password);
        //调用service查询
        User user = service.findByUsernameAndPwd(username,password);
        if (user!= null){
            req.getSession().setAttribute("user",user);
            resp.getWriter().write("true");
        }else{
            resp.getWriter().write("false");
        }

    }
}
